package com.briup.estore.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter("*.jsp")
public class BathPathFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        // 提前获得项目的相对路径点，后面的页面可以直接取
        // 获得相对路径点
        HttpServletRequest req = (HttpServletRequest)request;
        // http://localhost:端口号/项目名称/
        String basePath = req.getScheme()+"://"+
                req.getServerName()+":"+req.getServerPort()+
                req.getContextPath()+"/";
        System.out.println(basePath);
        // 存入到session中
        req.getSession().setAttribute("basePath",basePath);

    }

    @Override
    public void destroy() {

    }
}
